package com.example.mobile2021606170hsy0408;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private CheckBox chkboxMainYinqi;
    private CheckBox chkboxMainFangx;
    private CheckBox chkboxMainBoli;
    private Button btMainBuy;
    private TextView tvMainTip;
    private TextView tvMainResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        chkboxMainYinqi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    tvMainResult.setText("选中：" + buttonView.getText().toString());
                } else {
                    tvMainResult.setText("取消选中：" + buttonView.getText().toString());

                }
            }
        });

        chkboxMainFangx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    tvMainResult.setText("选中：" + buttonView.getText().toString());
                } else {
                    tvMainResult.setText("取消选中：" + buttonView.getText().toString());
                }
            }
        });

        chkboxMainBoli.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    tvMainResult.setText("选中：" + buttonView.getText().toString());
                } else {
                    tvMainResult.setText("取消选中：" + buttonView.getText().toString());
                }
            }
        });
        btMainBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String  msg ="选中：";
                if (chkboxMainYinqi.isChecked()) {
                    tvMainResult.setText(chkboxMainYinqi.getText().toString());
                } else {


                    tvMainResult.setText(msg);
                }
            }
        });
    }

                private void initView () {
                    tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
                    chkboxMainYinqi = (CheckBox) findViewById(R.id.chkbox_main_yinqi);
                    chkboxMainFangx = (CheckBox) findViewById(R.id.chkbox_main_fangx);
                    chkboxMainBoli = (CheckBox) findViewById(R.id.chkbox_main_boli);
                    btMainBuy = (Button) findViewById(R.id.bt_main_buy);
                    tvMainTip = (TextView) findViewById(R.id.tv_main_tip);
                    tvMainResult = (TextView) findViewById(R.id.tv_main_result);
                }
            }

